const {
  baseUrl,
  getRequest,
  postRequest
} = require("../../../utils/request.js")
const {
  mock_flag,
  login_flag
} = require("../../../data/index.js")
Page({
  data: {
    feedbackName: '',
    feedbackEmail: '',
    feedbackContent: ''
  },
  /**
   * 表单输入
   */
  // 姓名输入框内容变化时的处理函数
  onNameInput: function (e) {
    this.setData({
      feedbackName: e.detail.value
    });
  },
  // 邮箱输入框内容变化时的处理函数
  onEmailInput: function (e) {
    this.setData({
      feedbackEmail: e.detail.value
    });
  },
  // 内容输入框内容变化时的处理函数
  onContentInput: function (e) {
    this.setData({
      feedbackContent: e.detail.value
    });
  },
  // 提交反馈的处理函数
  submitFeedback: function () {
    const name = this.data.feedbackName;
    const email = this.data.feedbackEmail;
    const content = this.data.feedbackContent;
    if (name.trim() === '' || email.trim() === '' || content.trim() === '') {
      wx.showToast({
        title: '请填写完整信息',
        icon: 'none'
      });
      return;
    }
    if (mock_flag) {
      wx.showToast({
        title: '反馈提交成功',
        icon: 'success'
      });
      // 清空输入框
      this.setData({
        feedbackName: '',
        feedbackEmail: '',
        feedbackContent: ''
      });
    }
    if (!mock_flag) {
      this.http_feedback_add()
    }
  },
  /**
   * 网络请求
   */
  //查询用户详情
  http_feedback_add() {
    postRequest(baseUrl + "/front/feedback/add", {
      feedbackName: this.data.feedbackName,
      feedbackEmail: this.data.feedbackEmail,
      feedbackContent: this.data.feedbackContent,
    }).then(res => {
      //console.log(res.data)
      if (res.code == 200) {
        wx.showToast({
          title: '反馈提交成功',
          icon: 'success'
        });
        // 清空输入框
        this.setData({
          feedbackName: '',
          feedbackEmail: '',
          feedbackContent: ''
        });
      }
    })
  },
});